/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.cpu.z80.processor;

/**
 *
 * @author kennux
 */

import com.memory.Memory;
public class Z80Manager {
    private Thread t;
    private int cpf;
    private int wpf;
    private Z80Core CPU;
    private boolean isRunning;

    Runnable runner = new Runnable() {
        public void run() {
            while(isRunning) {
                CPU.addCycles(cpf);
                try {
                    Thread.sleep(wpf);
                } catch (java.lang.InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    };

    public Z80Manager(int Mhz, int FPS) {
        int tempCycles = Mhz * 1024 * 1024;
        cpf = tempCycles / FPS;
        wpf = 1000 / FPS;
        CPU = new Z80Core();
        isRunning = true;
        CPU.startCpu((short)100, new Memory((short)1337));
        t = new Thread(runner);
        t.start();
    }
}
